package com.dragon.pear.config;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;

import java.io.IOException;

/**
 * @author Chris Chan
 * Create On 2025/8/9 上午12:53
 * Use for:
 * Explain:
 */
@Slf4j
@Order(1)
@WebFilter(urlPatterns = "/*")
public class DebugFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        // 取出请求路径
        HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
        String requestURI = httpServletRequest.getRequestURI();
        log.info("requestURI: {}", requestURI);
        // 取出Authorization
        String authorization = httpServletRequest.getHeader("Authorization");
        if (authorization != null) {
            log.info("authorization: \n{}", authorization);
        }
        filterChain.doFilter(servletRequest, servletResponse);
    }
}
